package com.zhida.smartcontrol;

import android.app.Application;

import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import com.jay.tools.configure.Party;
import com.jay.tools.utils.SharedUtil;
import com.jay.tools.utils.TimeUtil;
import com.tan.fonticon.Iconify;
import com.yanzhenjie.kalle.Kalle;
import com.yanzhenjie.kalle.KalleConfig;
import com.yanzhenjie.kalle.connect.BroadcastNetwork;
import com.zhida.smartcontrol.common.icon.MyIconModule;
import com.zhida.smartcontrol.knet.LogInterceptor;
import com.zhida.smartcontrol.knet.OkHttpCustomFactory;

import java.util.concurrent.TimeUnit;

import me.jessyan.autosize.AutoSizeConfig;

public class SmartApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        Party.init(getApplicationContext())
                .configure();

        configKalle();

        configBaiduMap();

        configAutoSize();

        Iconify.with(new MyIconModule());

        SharedUtil.initSharedPre(getApplicationContext());

//        Fragmentation.builder()
//                .stackViewMode(Fragmentation.BUBBLE)
//                .debug(true)
//                .install();
    }

    private void configAutoSize() {
        AutoSizeConfig.getInstance().setCustomFragment(true);
    }

    private void configKalle() {
        KalleConfig config = KalleConfig.newBuilder()
                .network(new BroadcastNetwork(this))
                .connectFactory(OkHttpCustomFactory.newBuilder().build())
                .readTimeout(5, TimeUnit.MINUTES)
                .readTimeout(5, TimeUnit.MINUTES)
                .connectionTimeout(5, TimeUnit.MINUTES)
//                .addInterceptor(new LoggerInterceptor("",true)) // Kalle自带日志拦截器
                .addInterceptor(new LogInterceptor("SmartApplication", true))
                .build();

        Kalle.setConfig(config);
    }

    private void configBaiduMap() {
        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        SDKInitializer.initialize(this);
        //自4.3.0起，百度地图SDK所有接口均支持百度坐标和国测局坐标，用此方法设置您使用的坐标类型.
        //包括BD09LL和GCJ02两种坐标，默认是BD09LL坐标。
        SDKInitializer.setCoordType(CoordType.BD09LL);
    }


}
